/** @file MapLoader.qml
@brief The Qt-Complex special loader for the map object.

Do not use this loader for the other framework objects. Use Loader instead.

@todo Manage map signals to interact with map navigation from the application.
@todo Add map start position and location in the theme properties.

@authorname \n
@licenseversion \n
@actualversion - @dateupdate

@licensenote
*/

import QtQuick 1.0

// The loader element surrounded by its item
Item {
    id: itemLoader

    // Loader properties to be assigned in the program
    property string obj: ""     // Object to load
    property string urlObj:  "" // Object loaded from a http url
    property string theme: ""   // Theme name
    // The following properties are used by the loaded

    // The used properties depends by the object type.
    property string obj_string: ""  // Generic string assigned to fields, buttons, etc.
    property string obj_message: ""  // Generic message assigne to text

    // Property values to contain route and location information
    // The location default position is preset as the program needs
    // but can be parametrized too.
    property string location: "Istanbul"
    property double lat: 41.0409106
    property double lon: 28.9861692
    property double zoom: 10

    // The signals connected with the object types
    signal clicked

    width: parent.width
    height: parent.height

    Loader {
        id:objLoad

        // Set of inline functions returning the requested property
        function getString() { return itemLoader.obj_string; }
        function getMessage() { return itemLoader.obj_message; }
        function getWidth() { return itemLoader.width; }
        function getHeight() { return itemLoader.height; }

        /**
        @fn getTheme()
        @brief Returns the theme name of the loader

        This function is used by the loaded object for the
        correct property assignement.
        @return theme Them theme property string
        */
        function getTheme() {
            return itemLoader.theme;
        }

        /**
        @fn objDestroy()
        @brief destroys the loaded object and free the associated resources.
        */
        function objDestroy() {
            source = "";
        }

        // The object source definition
        source: (itemLoader.obj == "") ? getBaseUrl() + itemLoader.urlObj + ".qml": itemLoader.obj + ".qml";

        // When loaded the map is set to the defaul starting location
        onLoaded: {
            objLoad.item.setLocation(itemLoader.lat, itemLoader.lon);
            objLoad.item.setMapZoom(itemLoader.zoom);
        }
    }

    // The connections to the possible signals returned by the objects
    Connections {
        target: objLoad.item
        // The ignoerUnknownSignals is set to true because not all the loadable objects
        // manages the same signals.
        ignoreUnknownSignals: true
        // Signal returned by buttons and objects that manages buttonclick()
        onObjClicked: { itemLoader.clicked(); }
    }
}
